<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // function Person() {
    //   this.name = 'John';
    // }
    // let instance = null;
    // const SingleTon = ()=>{

    //   if(!instance) return instance = new Person();
    //   return instance
    // }
    const Person = (function() {
      function Person() {
        this.name = 'John';
      }
      let instance = null;
      return function singleTon () {
        if(!instance) return instance = new Person();
        return instance
      }

    
    })()


        //  new 与不new都会返回instance实例
    let p1  = new Person();
    let p2  =new Person();
    console.log(p1==p2);
  </script>
</body>
</html>